<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>date.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_date_date.js.html">date.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Functions and objects for date representation and manipulation.
<a name="line17"></a> *
<a name="line18"></a> * @author eae@google.com (Emil A Eklund)
<a name="line19"></a> * @author pallosp@google.com (Peter Pallos)
<a name="line20"></a> */
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.date&#39;);
<a name="line23"></a>goog.provide(&#39;goog.date.Date&#39;);
<a name="line24"></a>goog.provide(&#39;goog.date.DateTime&#39;);
<a name="line25"></a>goog.provide(&#39;goog.date.Interval&#39;);
<a name="line26"></a>goog.provide(&#39;goog.date.month&#39;);
<a name="line27"></a>goog.provide(&#39;goog.date.weekDay&#39;);
<a name="line28"></a>
<a name="line29"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line30"></a>goog.require(&#39;goog.date.DateLike&#39;);
<a name="line31"></a>goog.require(&#39;goog.i18n.DateTimeSymbols&#39;);
<a name="line32"></a>goog.require(&#39;goog.string&#39;);
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * Constants for weekdays.
<a name="line37"></a> * @enum {number}
<a name="line38"></a> */
<a name="line39"></a>goog.date.weekDay = {
<a name="line40"></a>  MON: 0,
<a name="line41"></a>  TUE: 1,
<a name="line42"></a>  WED: 2,
<a name="line43"></a>  THU: 3,
<a name="line44"></a>  FRI: 4,
<a name="line45"></a>  SAT: 5,
<a name="line46"></a>  SUN: 6
<a name="line47"></a>};
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>/**
<a name="line51"></a> * Constants for months.
<a name="line52"></a> * @enum {number}
<a name="line53"></a> */
<a name="line54"></a>goog.date.month = {
<a name="line55"></a>  JAN: 0,
<a name="line56"></a>  FEB: 1,
<a name="line57"></a>  MAR: 2,
<a name="line58"></a>  APR: 3,
<a name="line59"></a>  MAY: 4,
<a name="line60"></a>  JUN: 5,
<a name="line61"></a>  JUL: 6,
<a name="line62"></a>  AUG: 7,
<a name="line63"></a>  SEP: 8,
<a name="line64"></a>  OCT: 9,
<a name="line65"></a>  NOV: 10,
<a name="line66"></a>  DEC: 11
<a name="line67"></a>};
<a name="line68"></a>
<a name="line69"></a>
<a name="line70"></a>/**
<a name="line71"></a> * Formats a month/year string.
<a name="line72"></a> * Example: &quot;January 2008&quot;
<a name="line73"></a> *
<a name="line74"></a> * @param {string} monthName The month name to use in the result.
<a name="line75"></a> * @param {number} yearNum The numeric year to use in the result.
<a name="line76"></a> * @return {string} A formatted month/year string.
<a name="line77"></a> */
<a name="line78"></a>goog.date.formatMonthAndYear = function(monthName, yearNum) {
<a name="line79"></a>  /** @desc Month/year format given the month name and the numeric year. */
<a name="line80"></a>  var MSG_MONTH_AND_YEAR = goog.getMsg(
<a name="line81"></a>      &#39;{$monthName} {$yearNum}&#39;,
<a name="line82"></a>      { &#39;monthName&#39; : monthName, &#39;yearNum&#39; : yearNum });
<a name="line83"></a>  return MSG_MONTH_AND_YEAR;
<a name="line84"></a>};
<a name="line85"></a>
<a name="line86"></a>
<a name="line87"></a>/**
<a name="line88"></a> * Regular expression for splitting date parts from ISO 8601 styled string.
<a name="line89"></a> * Examples: &#39;20060210&#39; or &#39;2005-02-22&#39; or &#39;20050222&#39; or &#39;2005-08&#39;
<a name="line90"></a> * or &#39;2005-W22&#39; or &#39;2005W22&#39; or &#39;2005-W22-4&#39;, etc.
<a name="line91"></a> * For explanation and more examples, see:
<a name="line92"></a> * {@link http://en.wikipedia.org/wiki/ISO_8601}
<a name="line93"></a> *
<a name="line94"></a> * @type {RegExp}
<a name="line95"></a> * @private
<a name="line96"></a> */
<a name="line97"></a>goog.date.splitDateStringRegex_ = new RegExp(
<a name="line98"></a>    &#39;^(\\d{4})(?:(?:-?(\\d{2})(?:-?(\\d{2}))?)|&#39; +
<a name="line99"></a>    &#39;(?:-?(\\d{3}))|(?:-?W(\\d{2})(?:-?([1-7]))?))?$&#39;);
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Regular expression for splitting time parts from ISO 8601 styled string.
<a name="line104"></a> * Examples: &#39;18:46:39.994&#39; or &#39;184639.994&#39;
<a name="line105"></a> *
<a name="line106"></a> * @type {RegExp}
<a name="line107"></a> * @private
<a name="line108"></a> */
<a name="line109"></a>goog.date.splitTimeStringRegex_ =
<a name="line110"></a>    /^(\d{2})(?::?(\d{2})(?::?(\d{2})(\.\d+)?)?)?$/;
<a name="line111"></a>
<a name="line112"></a>
<a name="line113"></a>/**
<a name="line114"></a> * Regular expression for splitting timezone parts from ISO 8601 styled string.
<a name="line115"></a> * Example: The part after the &#39;+&#39; in &#39;18:46:39+07:00&#39;.  Or &#39;09:30Z&#39; (UTC).
<a name="line116"></a> *
<a name="line117"></a> * @type {RegExp}
<a name="line118"></a> * @private
<a name="line119"></a> */
<a name="line120"></a>goog.date.splitTimezoneStringRegex_ = /Z|(?:([-+])(\d{2})(?::?(\d{2}))?)$/;
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * Regular expression for splitting duration parts from ISO 8601 styled string.
<a name="line125"></a> * Example: &#39;-P1Y2M3DT4H5M6.7S&#39;
<a name="line126"></a> *
<a name="line127"></a> * @type {RegExp}
<a name="line128"></a> * @private
<a name="line129"></a> */
<a name="line130"></a>goog.date.splitDurationRegex_ = new RegExp(
<a name="line131"></a>    &#39;^(-)?P(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?&#39; +
<a name="line132"></a>    &#39;(T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+(?:\\.\\d+)?)S)?)?$&#39;);
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>/**
<a name="line136"></a> * Returns whether the given year is a leap year.
<a name="line137"></a> *
<a name="line138"></a> * @param {number} year Year part of date.
<a name="line139"></a> * @return {boolean} Whether the given year is a leap year.
<a name="line140"></a> */
<a name="line141"></a>goog.date.isLeapYear = function(year) {
<a name="line142"></a>  // Leap year logic; the 4-100-400 rule
<a name="line143"></a>  return year % 4 == 0 &amp;&amp; (year % 100 != 0 || year % 400 == 0);
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * Returns whether the given year is a long ISO year.
<a name="line149"></a> * See {@link http://www.phys.uu.nl/~vgent/calendar/isocalendar_text3.htm}.
<a name="line150"></a> *
<a name="line151"></a> * @param {number} year Full year part of date.
<a name="line152"></a> * @return {boolean} Whether the given year is a long ISO year.
<a name="line153"></a> */
<a name="line154"></a>goog.date.isLongIsoYear = function(year) {
<a name="line155"></a>  var n = 5 * year + 12 - 4 * (Math.floor(year / 100) - Math.floor(year / 400));
<a name="line156"></a>  n += Math.floor((year - 100) / 400) - Math.floor((year - 102) / 400);
<a name="line157"></a>  n += Math.floor((year - 200) / 400) - Math.floor((year - 199) / 400);
<a name="line158"></a>
<a name="line159"></a>  return n % 28 &lt; 5;
<a name="line160"></a>};
<a name="line161"></a>
<a name="line162"></a>
<a name="line163"></a>/**
<a name="line164"></a> * Returns the number of days for a given month.
<a name="line165"></a> *
<a name="line166"></a> * @param {number} year Year part of date.
<a name="line167"></a> * @param {number} month Month part of date.
<a name="line168"></a> * @return {number} The number of days for the given month.
<a name="line169"></a> */
<a name="line170"></a>goog.date.getNumberOfDaysInMonth = function(year, month) {
<a name="line171"></a>  switch (month) {
<a name="line172"></a>    case goog.date.month.FEB:
<a name="line173"></a>      return goog.date.isLeapYear(year) ? 29 : 28;
<a name="line174"></a>    case goog.date.month.JUN:
<a name="line175"></a>    case goog.date.month.SEP:
<a name="line176"></a>    case goog.date.month.NOV:
<a name="line177"></a>    case goog.date.month.APR:
<a name="line178"></a>      return 30;
<a name="line179"></a>  }
<a name="line180"></a>  return 31;
<a name="line181"></a>};
<a name="line182"></a>
<a name="line183"></a>
<a name="line184"></a>/**
<a name="line185"></a> * Returns true if the 2 dates are in the same day.
<a name="line186"></a> * @param {goog.date.DateLike} date The time to check.
<a name="line187"></a> * @param {goog.date.DateLike=} opt_now The current time.
<a name="line188"></a> * @return {boolean} Whether the dates are on the same day.
<a name="line189"></a> */
<a name="line190"></a>goog.date.isSameDay = function(date, opt_now) {
<a name="line191"></a>  var now = opt_now || new Date(goog.now());
<a name="line192"></a>  return date.getDate() == now.getDate() &amp;&amp;
<a name="line193"></a>      goog.date.isSameMonth(date, now);
<a name="line194"></a>};
<a name="line195"></a>
<a name="line196"></a>
<a name="line197"></a>/**
<a name="line198"></a> * Returns true if the 2 dates are in the same month.
<a name="line199"></a> * @param {goog.date.DateLike} date The time to check.
<a name="line200"></a> * @param {goog.date.DateLike=} opt_now The current time.
<a name="line201"></a> * @return {boolean} Whether the dates are in the same calendar month.
<a name="line202"></a> */
<a name="line203"></a>goog.date.isSameMonth = function(date, opt_now) {
<a name="line204"></a>  var now = opt_now || new Date(goog.now());
<a name="line205"></a>  return date.getMonth() == now.getMonth() &amp;&amp;
<a name="line206"></a>      goog.date.isSameYear(date, now);
<a name="line207"></a>};
<a name="line208"></a>
<a name="line209"></a>
<a name="line210"></a>/**
<a name="line211"></a> * Returns true if the 2 dates are in the same year.
<a name="line212"></a> * @param {goog.date.DateLike} date The time to check.
<a name="line213"></a> * @param {goog.date.DateLike=} opt_now The current time.
<a name="line214"></a> * @return {boolean} Whether the dates are in the same calendar year.
<a name="line215"></a> */
<a name="line216"></a>goog.date.isSameYear = function(date, opt_now) {
<a name="line217"></a>  var now = opt_now || new Date(goog.now());
<a name="line218"></a>  return date.getFullYear() == now.getFullYear();
<a name="line219"></a>};
<a name="line220"></a>
<a name="line221"></a>
<a name="line222"></a>/**
<a name="line223"></a> * Static function for week number calculation. ISO 8601 implementation.
<a name="line224"></a> *
<a name="line225"></a> * @param {number} year Year part of date.
<a name="line226"></a> * @param {number} month Month part of date (0-11).
<a name="line227"></a> * @param {number} date Day part of date (1-31).
<a name="line228"></a> * @param {number=} opt_weekDay Cut off weekday, defaults to Thursday.
<a name="line229"></a> * @param {number=} opt_firstDayOfWeek First day of the week, defaults to
<a name="line230"></a> *     Monday.
<a name="line231"></a> *     Monday=0, Sunday=6.
<a name="line232"></a> * @return {number} The week number (1-53).
<a name="line233"></a> */
<a name="line234"></a>goog.date.getWeekNumber = function(year, month, date, opt_weekDay,
<a name="line235"></a>    opt_firstDayOfWeek) {
<a name="line236"></a>  var d = new Date(year, month, date);
<a name="line237"></a>
<a name="line238"></a>  // Default to Thursday for cut off as per ISO 8601.
<a name="line239"></a>  var cutoff = opt_weekDay || goog.date.weekDay.THU;
<a name="line240"></a>
<a name="line241"></a>  // Default to Monday for first day of the week as per ISO 8601.
<a name="line242"></a>  var firstday = opt_firstDayOfWeek || goog.date.weekDay.MON;
<a name="line243"></a>
<a name="line244"></a>  // 1 day in milliseconds.
<a name="line245"></a>  var ONE_DAY = 24 * 60 * 60 * 1000;
<a name="line246"></a>
<a name="line247"></a>  // The d.getDay() has to be converted first to ISO weekday (Monday=0).
<a name="line248"></a>  var isoday = (d.getDay() + 6) % 7;
<a name="line249"></a>
<a name="line250"></a>  // Position of given day in the picker grid w.r.t. first day of week
<a name="line251"></a>  var daypos = (isoday - firstday + 7) % 7;
<a name="line252"></a>
<a name="line253"></a>  // Position of cut off day in the picker grid w.r.t. first day of week
<a name="line254"></a>  var cutoffpos = (cutoff - firstday + 7) % 7;
<a name="line255"></a>
<a name="line256"></a>  // Unix timestamp of the midnight of the cutoff day in the week of &#39;d&#39;.
<a name="line257"></a>  // There might be +-1 hour shift in the result due to the daylight saving,
<a name="line258"></a>  // but it doesn&#39;t affect the year.
<a name="line259"></a>  var cutoffSameWeek = d.valueOf() + (cutoffpos - daypos) * ONE_DAY;
<a name="line260"></a>
<a name="line261"></a>  // Unix timestamp of January 1 in the year of &#39;cutoffSameWeek&#39;.
<a name="line262"></a>  var jan1 = new Date(new Date(cutoffSameWeek).getFullYear(), 0, 1).valueOf();
<a name="line263"></a>
<a name="line264"></a>  // Number of week. The round() eliminates the effect of daylight saving.
<a name="line265"></a>  return Math.floor(Math.round((cutoffSameWeek - jan1) / ONE_DAY) / 7) + 1;
<a name="line266"></a>};
<a name="line267"></a>
<a name="line268"></a>
<a name="line269"></a>/**
<a name="line270"></a> * Creates a DateTime from a datetime string expressed in ISO 8601 format.
<a name="line271"></a> *
<a name="line272"></a> * @param {string} formatted A date or datetime expressed in ISO 8601 format.
<a name="line273"></a> * @return {goog.date.DateTime} Parsed date or null if parse fails.
<a name="line274"></a> */
<a name="line275"></a>goog.date.fromIsoString = function(formatted) {
<a name="line276"></a>  var ret = new goog.date.DateTime(2000);
<a name="line277"></a>  return goog.date.setIso8601DateTime(ret, formatted) ? ret : null;
<a name="line278"></a>};
<a name="line279"></a>
<a name="line280"></a>
<a name="line281"></a>/**
<a name="line282"></a> * Parses a datetime string expressed in ISO 8601 format. Overwrites the date
<a name="line283"></a> * and optionally the time part of the given object with the parsed values.
<a name="line284"></a> *
<a name="line285"></a> * @param {!goog.date.DateTime} dateTime Object whose fields will be set.
<a name="line286"></a> * @param {string} formatted A date or datetime expressed in ISO 8601 format.
<a name="line287"></a> * @return {boolean} Whether the parsing succeeded.
<a name="line288"></a> */
<a name="line289"></a>goog.date.setIso8601DateTime = function(dateTime, formatted) {
<a name="line290"></a>  formatted = goog.string.trim(formatted);
<a name="line291"></a>  var delim = formatted.indexOf(&#39;T&#39;) == -1 ? &#39; &#39; : &#39;T&#39;;
<a name="line292"></a>  var parts = formatted.split(delim);
<a name="line293"></a>  return goog.date.setIso8601DateOnly_(dateTime, parts[0]) &amp;&amp;
<a name="line294"></a>      (parts.length &lt; 2 || goog.date.setIso8601TimeOnly_(dateTime, parts[1]));
<a name="line295"></a>};
<a name="line296"></a>
<a name="line297"></a>
<a name="line298"></a>/**
<a name="line299"></a> * Sets date fields based on an ISO 8601 format string.
<a name="line300"></a> *
<a name="line301"></a> * @param {!goog.date.DateTime} d Object whose fields will be set.
<a name="line302"></a> * @param {string} formatted A date expressed in ISO 8601 format.
<a name="line303"></a> * @return {boolean} Whether the parsing succeeded.
<a name="line304"></a> * @private
<a name="line305"></a> */
<a name="line306"></a>goog.date.setIso8601DateOnly_ = function(d, formatted) {
<a name="line307"></a>  // split the formatted ISO date string into its date fields
<a name="line308"></a>  var parts = formatted.match(goog.date.splitDateStringRegex_);
<a name="line309"></a>  if (!parts) {
<a name="line310"></a>    return false;
<a name="line311"></a>  }
<a name="line312"></a>
<a name="line313"></a>  var year = Number(parts[1]);
<a name="line314"></a>  var month = Number(parts[2]);
<a name="line315"></a>  var date = Number(parts[3]);
<a name="line316"></a>  var dayOfYear = Number(parts[4]);
<a name="line317"></a>  var week = Number(parts[5]);
<a name="line318"></a>  // ISO weekdays start with 1, native getDay() values start with 0
<a name="line319"></a>  var dayOfWeek = Number(parts[6]) || 1;
<a name="line320"></a>
<a name="line321"></a>  d.setFullYear(year);
<a name="line322"></a>
<a name="line323"></a>  if (dayOfYear) {
<a name="line324"></a>    d.setDate(1);
<a name="line325"></a>    d.setMonth(0);
<a name="line326"></a>    var offset = dayOfYear - 1; // offset, so 1-indexed, i.e., skip day 1
<a name="line327"></a>    d.add(new goog.date.Interval(goog.date.Interval.DAYS, offset));
<a name="line328"></a>  } else if (week) {
<a name="line329"></a>    goog.date.setDateFromIso8601Week_(d, week, dayOfWeek);
<a name="line330"></a>  } else {
<a name="line331"></a>    if (month) {
<a name="line332"></a>      d.setDate(1);
<a name="line333"></a>      d.setMonth(month - 1);
<a name="line334"></a>    }
<a name="line335"></a>    if (date) {
<a name="line336"></a>      d.setDate(date);
<a name="line337"></a>    }
<a name="line338"></a>  }
<a name="line339"></a>
<a name="line340"></a>  return true;
<a name="line341"></a>};
<a name="line342"></a>
<a name="line343"></a>
<a name="line344"></a>/**
<a name="line345"></a> * Sets date fields based on an ISO 8601 week string.
<a name="line346"></a> * See {@link http://en.wikipedia.org/wiki/ISO_week_date}, &quot;Relation with the
<a name="line347"></a> * Gregorian Calendar&quot;.  The first week of a new ISO year is the week with the
<a name="line348"></a> * majority of its days in the new Gregorian year.  I.e., ISO Week 1&#39;s Thursday
<a name="line349"></a> * is in that year.  ISO weeks always start on Monday. So ISO Week 1 can
<a name="line350"></a> * contain a few days from the previous Gregorian year.  And ISO weeks always
<a name="line351"></a> * end on Sunday, so the last ISO week (Week 52 or 53) can have a few days from
<a name="line352"></a> * the following Gregorian year.
<a name="line353"></a> * Example: &#39;1997-W01&#39; lasts from 1996-12-30 to 1997-01-05.  January 1, 1997 is
<a name="line354"></a> * a Wednesday. So W01&#39;s Monday is Dec.30, 1996, and Sunday is January 5, 1997.
<a name="line355"></a> *
<a name="line356"></a> * @param {goog.date.DateTime} d Object whose fields will be set.
<a name="line357"></a> * @param {number} week ISO week number.
<a name="line358"></a> * @param {number} dayOfWeek ISO day of week.
<a name="line359"></a> * @private
<a name="line360"></a> */
<a name="line361"></a>goog.date.setDateFromIso8601Week_ = function(d, week, dayOfWeek) {
<a name="line362"></a>  // calculate offset for first week
<a name="line363"></a>  d.setMonth(0);
<a name="line364"></a>  d.setDate(1);
<a name="line365"></a>  var jsDay = d.getDay();
<a name="line366"></a>  // switch Sunday (0) to index 7; ISO days are 1-indexed
<a name="line367"></a>  var jan1WeekDay = jsDay || 7;
<a name="line368"></a>
<a name="line369"></a>  var THURSDAY = 4;
<a name="line370"></a>  if (jan1WeekDay &lt;= THURSDAY) {
<a name="line371"></a>    // was extended back to Monday
<a name="line372"></a>    var startDelta = 1 - jan1WeekDay; // e.g., Thu(4) ==&gt; -3
<a name="line373"></a>  } else {
<a name="line374"></a>    // was extended forward to Monday
<a name="line375"></a>    startDelta = 8 - jan1WeekDay; // e.g., Fri(5) ==&gt; +3
<a name="line376"></a>  }
<a name="line377"></a>
<a name="line378"></a>  // find the absolute number of days to offset from the start of year
<a name="line379"></a>  // to arrive close to the Gregorian equivalent (pending adjustments above)
<a name="line380"></a>  // Note: decrement week multiplier by one because 1st week is
<a name="line381"></a>  // represented by dayOfWeek value
<a name="line382"></a>  var absoluteDays = Number(dayOfWeek) + (7 * (Number(week) - 1));
<a name="line383"></a>
<a name="line384"></a>  // convert from ISO weekday format to Gregorian calendar date
<a name="line385"></a>  // note: subtract 1 because 1-indexed; offset should not include 1st of month
<a name="line386"></a>  var delta = startDelta + absoluteDays - 1;
<a name="line387"></a>  var interval = new goog.date.Interval(goog.date.Interval.DAYS, delta);
<a name="line388"></a>  d.add(interval);
<a name="line389"></a>};
<a name="line390"></a>
<a name="line391"></a>
<a name="line392"></a>/**
<a name="line393"></a> * Sets time fields based on an ISO 8601 format string.
<a name="line394"></a> * Note: only time fields, not date fields.
<a name="line395"></a> *
<a name="line396"></a> * @param {!goog.date.DateTime} d Object whose fields will be set.
<a name="line397"></a> * @param {string} formatted A time expressed in ISO 8601 format.
<a name="line398"></a> * @return {boolean} Whether the parsing succeeded.
<a name="line399"></a> * @private
<a name="line400"></a> */
<a name="line401"></a>goog.date.setIso8601TimeOnly_ = function(d, formatted) {
<a name="line402"></a>  // first strip timezone info from the end
<a name="line403"></a>  var parts = formatted.match(goog.date.splitTimezoneStringRegex_);
<a name="line404"></a>
<a name="line405"></a>  var offset = 0; // local time if no timezone info
<a name="line406"></a>  if (parts) {
<a name="line407"></a>    if (parts[0] != &#39;Z&#39;) {
<a name="line408"></a>      offset = parts[2] * 60 + Number(parts[3]);
<a name="line409"></a>      offset *= parts[1] == &#39;-&#39; ? 1 : -1;
<a name="line410"></a>    }
<a name="line411"></a>    offset -= d.getTimezoneOffset();
<a name="line412"></a>    formatted = formatted.substr(0, formatted.length - parts[0].length);
<a name="line413"></a>  }
<a name="line414"></a>
<a name="line415"></a>  // then work out the time
<a name="line416"></a>  parts = formatted.match(goog.date.splitTimeStringRegex_);
<a name="line417"></a>  if (!parts) {
<a name="line418"></a>    return false;
<a name="line419"></a>  }
<a name="line420"></a>
<a name="line421"></a>  d.setHours(Number(parts[1]));
<a name="line422"></a>  d.setMinutes(Number(parts[2]) || 0);
<a name="line423"></a>  d.setSeconds(Number(parts[3]) || 0);
<a name="line424"></a>  d.setMilliseconds(parts[4] ? parts[4] * 1000 : 0);
<a name="line425"></a>
<a name="line426"></a>  if (offset != 0) {
<a name="line427"></a>    // adjust the date and time according to the specified timezone
<a name="line428"></a>    d.setTime(d.getTime() + offset * 60000);
<a name="line429"></a>  }
<a name="line430"></a>
<a name="line431"></a>  return true;
<a name="line432"></a>};
<a name="line433"></a>
<a name="line434"></a>
<a name="line435"></a>
<a name="line436"></a>/**
<a name="line437"></a> * Class representing a date/time interval. Used for date calculations.
<a name="line438"></a> * &lt;pre&gt;
<a name="line439"></a> * new goog.date.Interval(0, 1) // One month
<a name="line440"></a> * new goog.date.Interval(0, 0, 3, 1) // Three days and one hour
<a name="line441"></a> * new goog.date.Interval(goog.date.Interval.DAYS, 1) // One day
<a name="line442"></a> * &lt;/pre&gt;
<a name="line443"></a> *
<a name="line444"></a> * @param {number|string=} opt_years Years or string representing date part.
<a name="line445"></a> * @param {number=} opt_months Months or number of whatever date part specified
<a name="line446"></a> *     by first parameter.
<a name="line447"></a> * @param {number=} opt_days Days.
<a name="line448"></a> * @param {number=} opt_hours Hours.
<a name="line449"></a> * @param {number=} opt_minutes Minutes.
<a name="line450"></a> * @param {number=} opt_seconds Seconds.
<a name="line451"></a> * @constructor
<a name="line452"></a> */
<a name="line453"></a>goog.date.Interval = function(opt_years, opt_months, opt_days, opt_hours,
<a name="line454"></a>                              opt_minutes, opt_seconds) {
<a name="line455"></a>  if (goog.isString(opt_years)) {
<a name="line456"></a>    var type = opt_years;
<a name="line457"></a>    var interval = /** @type {number} */ (opt_months);
<a name="line458"></a>    this.years = type == goog.date.Interval.YEARS ? interval : 0;
<a name="line459"></a>    this.months = type == goog.date.Interval.MONTHS ? interval : 0;
<a name="line460"></a>    this.days = type == goog.date.Interval.DAYS ? interval : 0;
<a name="line461"></a>    this.hours = type == goog.date.Interval.HOURS ? interval : 0;
<a name="line462"></a>    this.minutes = type == goog.date.Interval.MINUTES ? interval : 0;
<a name="line463"></a>    this.seconds = type == goog.date.Interval.SECONDS ? interval : 0;
<a name="line464"></a>  } else {
<a name="line465"></a>    this.years = /** @type {number} */ (opt_years) || 0;
<a name="line466"></a>    this.months = opt_months || 0;
<a name="line467"></a>    this.days = opt_days || 0;
<a name="line468"></a>    this.hours = opt_hours || 0;
<a name="line469"></a>    this.minutes = opt_minutes || 0;
<a name="line470"></a>    this.seconds = opt_seconds || 0;
<a name="line471"></a>  }
<a name="line472"></a>};
<a name="line473"></a>
<a name="line474"></a>
<a name="line475"></a>/**
<a name="line476"></a> * Parses an XML Schema duration (ISO 8601 extended).
<a name="line477"></a> * @see http://www.w3.org/TR/xmlschema-2/#duration
<a name="line478"></a> *
<a name="line479"></a> * @param  {string} duration An XML schema duration in textual format.
<a name="line480"></a> *     Recurring durations and weeks are not supported.
<a name="line481"></a> * @return {goog.date.Interval} The duration as a goog.date.Interval or null
<a name="line482"></a> *     if the parse fails.
<a name="line483"></a> */
<a name="line484"></a>goog.date.Interval.fromIsoString = function(duration) {
<a name="line485"></a>  var parts = duration.match(goog.date.splitDurationRegex_);
<a name="line486"></a>  if (!parts) {
<a name="line487"></a>    return null;
<a name="line488"></a>  }
<a name="line489"></a>
<a name="line490"></a>  var timeEmpty = !(parts[6] || parts[7] || parts[8]);
<a name="line491"></a>  var dateTimeEmpty = timeEmpty &amp;&amp; !(parts[2] || parts[3] || parts[4]);
<a name="line492"></a>  if (dateTimeEmpty || timeEmpty &amp;&amp; parts[5]) {
<a name="line493"></a>    return null;
<a name="line494"></a>  }
<a name="line495"></a>
<a name="line496"></a>  var negative = parts[1];
<a name="line497"></a>  var years = parseInt(parts[2], 10) || 0;
<a name="line498"></a>  var months = parseInt(parts[3], 10) || 0;
<a name="line499"></a>  var days = parseInt(parts[4], 10) || 0;
<a name="line500"></a>  var hours = parseInt(parts[6], 10) || 0;
<a name="line501"></a>  var minutes = parseInt(parts[7], 10) || 0;
<a name="line502"></a>  var seconds = parseFloat(parts[8]) || 0;
<a name="line503"></a>  return negative ? new goog.date.Interval(-years, -months, -days,
<a name="line504"></a>                                           -hours, -minutes, -seconds) :
<a name="line505"></a>                    new goog.date.Interval(years, months, days,
<a name="line506"></a>                                           hours, minutes, seconds);
<a name="line507"></a>};
<a name="line508"></a>
<a name="line509"></a>
<a name="line510"></a>/**
<a name="line511"></a> * Serializes goog.date.Interval into XML Schema duration (ISO 8601 extended).
<a name="line512"></a> * @see http://www.w3.org/TR/xmlschema-2/#duration
<a name="line513"></a> *
<a name="line514"></a> * @param {boolean=} opt_verbose Include zero fields in the duration string.
<a name="line515"></a> * @return {?string} An XML schema duration in ISO 8601 extended format,
<a name="line516"></a> *     or null if the interval contains both positive and negative fields.
<a name="line517"></a> */
<a name="line518"></a>goog.date.Interval.prototype.toIsoString = function(opt_verbose) {
<a name="line519"></a>  var minField = Math.min(this.years, this.months, this.days,
<a name="line520"></a>                          this.hours, this.minutes, this.seconds);
<a name="line521"></a>  var maxField = Math.max(this.years, this.months, this.days,
<a name="line522"></a>                          this.hours, this.minutes, this.seconds);
<a name="line523"></a>  if (minField &lt; 0 &amp;&amp; maxField &gt; 0) {
<a name="line524"></a>    return null;
<a name="line525"></a>  }
<a name="line526"></a>
<a name="line527"></a>  // Return 0 seconds if all fields are zero.
<a name="line528"></a>  if (!opt_verbose &amp;&amp; minField == 0 &amp;&amp; maxField == 0) {
<a name="line529"></a>    return &#39;PT0S&#39;;
<a name="line530"></a>  }
<a name="line531"></a>
<a name="line532"></a>  var res = [];
<a name="line533"></a>
<a name="line534"></a>  // Add sign and &#39;P&#39; prefix.
<a name="line535"></a>  if (minField &lt; 0) {
<a name="line536"></a>    res.push(&#39;-&#39;);
<a name="line537"></a>  }
<a name="line538"></a>  res.push(&#39;P&#39;);
<a name="line539"></a>
<a name="line540"></a>  // Add date.
<a name="line541"></a>  if (this.years || opt_verbose) {
<a name="line542"></a>    res.push(Math.abs(this.years) + &#39;Y&#39;);
<a name="line543"></a>  }
<a name="line544"></a>  if (this.months || opt_verbose) {
<a name="line545"></a>    res.push(Math.abs(this.months) + &#39;M&#39;);
<a name="line546"></a>  }
<a name="line547"></a>  if (this.days || opt_verbose) {
<a name="line548"></a>    res.push(Math.abs(this.days) + &#39;D&#39;);
<a name="line549"></a>  }
<a name="line550"></a>
<a name="line551"></a>  // Add time.
<a name="line552"></a>  if (this.hours || this.minutes || this.seconds || opt_verbose) {
<a name="line553"></a>    res.push(&#39;T&#39;);
<a name="line554"></a>    if (this.hours || opt_verbose) {
<a name="line555"></a>      res.push(Math.abs(this.hours) + &#39;H&#39;);
<a name="line556"></a>    }
<a name="line557"></a>    if (this.minutes || opt_verbose) {
<a name="line558"></a>      res.push(Math.abs(this.minutes) + &#39;M&#39;);
<a name="line559"></a>    }
<a name="line560"></a>    if (this.seconds || opt_verbose) {
<a name="line561"></a>      res.push(Math.abs(this.seconds) + &#39;S&#39;);
<a name="line562"></a>    }
<a name="line563"></a>  }
<a name="line564"></a>
<a name="line565"></a>  return res.join(&#39;&#39;);
<a name="line566"></a>};
<a name="line567"></a>
<a name="line568"></a>
<a name="line569"></a>/**
<a name="line570"></a> * Tests whether the given interval is equal to this interval.
<a name="line571"></a> * Note, this is a simple field-by-field comparison, it doesn&#39;t
<a name="line572"></a> * account for comparisons like &quot;12 months == 1 year&quot;.
<a name="line573"></a> *
<a name="line574"></a> * @param {goog.date.Interval} other The interval to test.
<a name="line575"></a> * @return {boolean} Whether the intervals are equal.
<a name="line576"></a> */
<a name="line577"></a>goog.date.Interval.prototype.equals = function(other) {
<a name="line578"></a>  return other.years == this.years &amp;&amp;
<a name="line579"></a>         other.months == this.months &amp;&amp;
<a name="line580"></a>         other.days == this.days &amp;&amp;
<a name="line581"></a>         other.hours == this.hours &amp;&amp;
<a name="line582"></a>         other.minutes == this.minutes &amp;&amp;
<a name="line583"></a>         other.seconds == this.seconds;
<a name="line584"></a>};
<a name="line585"></a>
<a name="line586"></a>
<a name="line587"></a>/**
<a name="line588"></a> * @return {!goog.date.Interval} A clone of the interval object.
<a name="line589"></a> */
<a name="line590"></a>goog.date.Interval.prototype.clone = function() {
<a name="line591"></a>  return new goog.date.Interval(
<a name="line592"></a>      this.years, this.months, this.days,
<a name="line593"></a>      this.hours, this.minutes, this.seconds);
<a name="line594"></a>};
<a name="line595"></a>
<a name="line596"></a>
<a name="line597"></a>/**
<a name="line598"></a> * Years constant for the date parts.
<a name="line599"></a> * @type {string}
<a name="line600"></a> */
<a name="line601"></a>goog.date.Interval.YEARS = &#39;y&#39;;
<a name="line602"></a>
<a name="line603"></a>
<a name="line604"></a>/**
<a name="line605"></a> * Months constant for the date parts.
<a name="line606"></a> * @type {string}
<a name="line607"></a> */
<a name="line608"></a>goog.date.Interval.MONTHS = &#39;m&#39;;
<a name="line609"></a>
<a name="line610"></a>
<a name="line611"></a>/**
<a name="line612"></a> * Days constant for the date parts.
<a name="line613"></a> * @type {string}
<a name="line614"></a> */
<a name="line615"></a>goog.date.Interval.DAYS = &#39;d&#39;;
<a name="line616"></a>
<a name="line617"></a>
<a name="line618"></a>/**
<a name="line619"></a> * Hours constant for the date parts.
<a name="line620"></a> * @type {string}
<a name="line621"></a> */
<a name="line622"></a>goog.date.Interval.HOURS = &#39;h&#39;;
<a name="line623"></a>
<a name="line624"></a>
<a name="line625"></a>/**
<a name="line626"></a> * Minutes constant for the date parts.
<a name="line627"></a> * @type {string}
<a name="line628"></a> */
<a name="line629"></a>goog.date.Interval.MINUTES = &#39;n&#39;;
<a name="line630"></a>
<a name="line631"></a>
<a name="line632"></a>/**
<a name="line633"></a> * Seconds constant for the date parts.
<a name="line634"></a> * @type {string}
<a name="line635"></a> */
<a name="line636"></a>goog.date.Interval.SECONDS = &#39;s&#39;;
<a name="line637"></a>
<a name="line638"></a>
<a name="line639"></a>/**
<a name="line640"></a> * @return {boolean} Whether all fields of the interval are zero.
<a name="line641"></a> */
<a name="line642"></a>goog.date.Interval.prototype.isZero = function() {
<a name="line643"></a>  return this.years == 0 &amp;&amp;
<a name="line644"></a>         this.months == 0 &amp;&amp;
<a name="line645"></a>         this.days == 0 &amp;&amp;
<a name="line646"></a>         this.hours == 0 &amp;&amp;
<a name="line647"></a>         this.minutes == 0 &amp;&amp;
<a name="line648"></a>         this.seconds == 0;
<a name="line649"></a>};
<a name="line650"></a>
<a name="line651"></a>
<a name="line652"></a>/**
<a name="line653"></a> * @return {!goog.date.Interval} Negative of this interval.
<a name="line654"></a> */
<a name="line655"></a>goog.date.Interval.prototype.getInverse = function() {
<a name="line656"></a>  return this.times(-1);
<a name="line657"></a>};
<a name="line658"></a>
<a name="line659"></a>
<a name="line660"></a>/**
<a name="line661"></a> * Calculates n * (this interval) by memberwise multiplication.
<a name="line662"></a> * @param {number} n An integer.
<a name="line663"></a> * @return {!goog.date.Interval} n * this.
<a name="line664"></a> */
<a name="line665"></a>goog.date.Interval.prototype.times = function(n) {
<a name="line666"></a>  return new goog.date.Interval(this.years * n,
<a name="line667"></a>                                this.months * n,
<a name="line668"></a>                                this.days * n,
<a name="line669"></a>                                this.hours * n,
<a name="line670"></a>                                this.minutes * n,
<a name="line671"></a>                                this.seconds * n);
<a name="line672"></a>};
<a name="line673"></a>
<a name="line674"></a>
<a name="line675"></a>/**
<a name="line676"></a> * Gets the total number of seconds in the time interval. Assumes that months
<a name="line677"></a> * and years are empty.
<a name="line678"></a> * @return {number} Total number of seconds in the interval.
<a name="line679"></a> */
<a name="line680"></a>goog.date.Interval.prototype.getTotalSeconds = function() {
<a name="line681"></a>  goog.asserts.assert(this.years == 0 &amp;&amp; this.months == 0);
<a name="line682"></a>  return ((this.days * 24 + this.hours) * 60 + this.minutes) * 60 +
<a name="line683"></a>      this.seconds;
<a name="line684"></a>};
<a name="line685"></a>
<a name="line686"></a>
<a name="line687"></a>/**
<a name="line688"></a> * Adds the Interval in the argument to this Interval field by field.
<a name="line689"></a> *
<a name="line690"></a> * @param {goog.date.Interval} interval The Interval to add.
<a name="line691"></a> */
<a name="line692"></a>goog.date.Interval.prototype.add = function(interval) {
<a name="line693"></a>  this.years += interval.years;
<a name="line694"></a>  this.months += interval.months;
<a name="line695"></a>  this.days += interval.days;
<a name="line696"></a>  this.hours += interval.hours;
<a name="line697"></a>  this.minutes += interval.minutes;
<a name="line698"></a>  this.seconds += interval.seconds;
<a name="line699"></a>};
<a name="line700"></a>
<a name="line701"></a>
<a name="line702"></a>
<a name="line703"></a>/**
<a name="line704"></a> * Class representing a date. Defaults to current date if none is specified.
<a name="line705"></a> *
<a name="line706"></a> * Implements most methods of the native js Date object (except the time related
<a name="line707"></a> * ones, {@see goog.date.DateTime}) and can be used interchangeably with it just
<a name="line708"></a> * as if goog.date.Date was a synonym of Date. To make this more transparent,
<a name="line709"></a> * Closure APIs should accept goog.date.DateLike instead of the real Date
<a name="line710"></a> * object.
<a name="line711"></a> *
<a name="line712"></a> * To allow goog.date.Date objects to be passed as arguments to methods
<a name="line713"></a> * expecting Date objects this class is marked as extending the built in Date
<a name="line714"></a> * object even though that&#39;s not strictly true.
<a name="line715"></a> *
<a name="line716"></a> * @param {number|Object=} opt_year Four digit year or a date-like object. If
<a name="line717"></a> *     not set, the created object will contain the date determined by
<a name="line718"></a> *     goog.now().
<a name="line719"></a> * @param {number=} opt_month Month, 0 = Jan, 11 = Dec.
<a name="line720"></a> * @param {number=} opt_date Date of month, 1 - 31.
<a name="line721"></a> * @constructor
<a name="line722"></a> * @see goog.date.DateTime
<a name="line723"></a> */
<a name="line724"></a>goog.date.Date = function(opt_year, opt_month, opt_date) {
<a name="line725"></a>  // goog.date.DateTime assumes that only this.date_ is added in this ctor.
<a name="line726"></a>  if (goog.isNumber(opt_year)) {
<a name="line727"></a>    this.date_ = new Date(opt_year, opt_month || 0, opt_date || 1);
<a name="line728"></a>    this.maybeFixDst_(opt_date || 1);
<a name="line729"></a>  } else if (goog.isObject(opt_year)) {
<a name="line730"></a>    this.date_ = new Date(opt_year.getFullYear(), opt_year.getMonth(),
<a name="line731"></a>                          opt_year.getDate());
<a name="line732"></a>    this.maybeFixDst_(opt_year.getDate());
<a name="line733"></a>  } else {
<a name="line734"></a>    this.date_ = new Date(goog.now());
<a name="line735"></a>    this.date_.setHours(0);
<a name="line736"></a>    this.date_.setMinutes(0);
<a name="line737"></a>    this.date_.setSeconds(0);
<a name="line738"></a>    this.date_.setMilliseconds(0);
<a name="line739"></a>  }
<a name="line740"></a>};
<a name="line741"></a>
<a name="line742"></a>
<a name="line743"></a>/**
<a name="line744"></a> * First day of week. 0 = Mon, 6 = Sun.
<a name="line745"></a> * @type {number}
<a name="line746"></a> * @private
<a name="line747"></a> */
<a name="line748"></a>goog.date.Date.prototype.firstDayOfWeek_ =
<a name="line749"></a>    goog.i18n.DateTimeSymbols.FIRSTDAYOFWEEK;
<a name="line750"></a>
<a name="line751"></a>
<a name="line752"></a>/**
<a name="line753"></a> * The cut off weekday used for week number calculations. 0 = Mon, 6 = Sun.
<a name="line754"></a> * @type {number}
<a name="line755"></a> * @private
<a name="line756"></a> */
<a name="line757"></a>goog.date.Date.prototype.firstWeekCutOffDay_ =
<a name="line758"></a>    goog.i18n.DateTimeSymbols.FIRSTWEEKCUTOFFDAY;
<a name="line759"></a>
<a name="line760"></a>
<a name="line761"></a>/**
<a name="line762"></a> * @return {!goog.date.Date} A clone of the date object.
<a name="line763"></a> */
<a name="line764"></a>goog.date.Date.prototype.clone = function() {
<a name="line765"></a>  var date = new goog.date.Date(this.date_);
<a name="line766"></a>  date.firstDayOfWeek_ = this.firstDayOfWeek_;
<a name="line767"></a>  date.firstWeekCutOffDay_ = this.firstWeekCutOffDay_;
<a name="line768"></a>
<a name="line769"></a>  return date;
<a name="line770"></a>};
<a name="line771"></a>
<a name="line772"></a>
<a name="line773"></a>/**
<a name="line774"></a> * @return {number} The four digit year of date.
<a name="line775"></a> */
<a name="line776"></a>goog.date.Date.prototype.getFullYear = function() {
<a name="line777"></a>  return this.date_.getFullYear();
<a name="line778"></a>};
<a name="line779"></a>
<a name="line780"></a>
<a name="line781"></a>/**
<a name="line782"></a> * Alias for getFullYear.
<a name="line783"></a> *
<a name="line784"></a> * @return {number} The four digit year of date.
<a name="line785"></a> * @see #getFullyear
<a name="line786"></a> */
<a name="line787"></a>goog.date.Date.prototype.getYear = function() {
<a name="line788"></a>  return this.getFullYear();
<a name="line789"></a>};
<a name="line790"></a>
<a name="line791"></a>
<a name="line792"></a>/**
<a name="line793"></a> * @return {goog.date.month} The month of date, 0 = Jan, 11 = Dec.
<a name="line794"></a> */
<a name="line795"></a>goog.date.Date.prototype.getMonth = function() {
<a name="line796"></a>  return /** @type {goog.date.month} */ (this.date_.getMonth());
<a name="line797"></a>};
<a name="line798"></a>
<a name="line799"></a>
<a name="line800"></a>/**
<a name="line801"></a> * @return {number} The date of month.
<a name="line802"></a> */
<a name="line803"></a>goog.date.Date.prototype.getDate = function() {
<a name="line804"></a>  return this.date_.getDate();
<a name="line805"></a>};
<a name="line806"></a>
<a name="line807"></a>
<a name="line808"></a>/**
<a name="line809"></a> * Returns the number of milliseconds since 1 January 1970 00:00:00.
<a name="line810"></a> *
<a name="line811"></a> * @return {number} The number of milliseconds since 1 January 1970 00:00:00.
<a name="line812"></a> */
<a name="line813"></a>goog.date.Date.prototype.getTime = function() {
<a name="line814"></a>  return this.date_.getTime();
<a name="line815"></a>};
<a name="line816"></a>
<a name="line817"></a>
<a name="line818"></a>/**
<a name="line819"></a> * @return {goog.date.weekDay} The day of week, US style. 0 = Sun, 6 = Sat.
<a name="line820"></a> */
<a name="line821"></a>goog.date.Date.prototype.getDay = function() {
<a name="line822"></a>  return /** @type {goog.date.weekDay} */ (this.date_.getDay());
<a name="line823"></a>};
<a name="line824"></a>
<a name="line825"></a>
<a name="line826"></a>/**
<a name="line827"></a> * @return {number} The day of week, ISO style. 0 = Mon, 6 = Sun.
<a name="line828"></a> */
<a name="line829"></a>goog.date.Date.prototype.getIsoWeekday = function() {
<a name="line830"></a>  return (this.getDay() + 6) % 7;
<a name="line831"></a>};
<a name="line832"></a>
<a name="line833"></a>
<a name="line834"></a>/**
<a name="line835"></a> * @return {number} The day of week according to firstDayOfWeek setting.
<a name="line836"></a> */
<a name="line837"></a>goog.date.Date.prototype.getWeekday = function() {
<a name="line838"></a>  return (this.getIsoWeekday() - this.firstDayOfWeek_ + 7) % 7;
<a name="line839"></a>};
<a name="line840"></a>
<a name="line841"></a>
<a name="line842"></a>/**
<a name="line843"></a> * @return {number} The four digit year of date according to universal time.
<a name="line844"></a> */
<a name="line845"></a>goog.date.Date.prototype.getUTCFullYear = function() {
<a name="line846"></a>  return this.date_.getUTCFullYear();
<a name="line847"></a>};
<a name="line848"></a>
<a name="line849"></a>
<a name="line850"></a>/**
<a name="line851"></a> * @return {goog.date.month} The month of date according to universal time,
<a name="line852"></a> *     0 = Jan, 11 = Dec.
<a name="line853"></a> */
<a name="line854"></a>goog.date.Date.prototype.getUTCMonth = function() {
<a name="line855"></a>  return /** @type {goog.date.month} */ (this.date_.getUTCMonth());
<a name="line856"></a>};
<a name="line857"></a>
<a name="line858"></a>
<a name="line859"></a>/**
<a name="line860"></a> * @return {number} The date of month according to universal time.
<a name="line861"></a> */
<a name="line862"></a>goog.date.Date.prototype.getUTCDate = function() {
<a name="line863"></a>  return this.date_.getUTCDate();
<a name="line864"></a>};
<a name="line865"></a>
<a name="line866"></a>
<a name="line867"></a>/**
<a name="line868"></a> * @return {goog.date.weekDay} The day of week according to universal time,
<a name="line869"></a> *     US style. 0 = Sun, 1 = Mon, 6 = Sat.
<a name="line870"></a> */
<a name="line871"></a>goog.date.Date.prototype.getUTCDay = function() {
<a name="line872"></a>  return /** @type {goog.date.weekDay} */ (this.date_.getDay());
<a name="line873"></a>};
<a name="line874"></a>
<a name="line875"></a>
<a name="line876"></a>/**
<a name="line877"></a> * @return {number} The hours value according to universal time.
<a name="line878"></a> */
<a name="line879"></a>goog.date.Date.prototype.getUTCHours = function() {
<a name="line880"></a>  return this.date_.getUTCHours();
<a name="line881"></a>};
<a name="line882"></a>
<a name="line883"></a>
<a name="line884"></a>/**
<a name="line885"></a> * @return {number} The hours value according to universal time.
<a name="line886"></a> */
<a name="line887"></a>goog.date.Date.prototype.getUTCMinutes = function() {
<a name="line888"></a>  return this.date_.getUTCMinutes();
<a name="line889"></a>};
<a name="line890"></a>
<a name="line891"></a>
<a name="line892"></a>/**
<a name="line893"></a> * @return {number} The day of week according to universal time, ISO style.
<a name="line894"></a> *     0 = Mon, 6 = Sun.
<a name="line895"></a> */
<a name="line896"></a>goog.date.Date.prototype.getUTCIsoWeekday = function() {
<a name="line897"></a>  return (this.date_.getUTCDay() + 6) % 7;
<a name="line898"></a>};
<a name="line899"></a>
<a name="line900"></a>
<a name="line901"></a>/**
<a name="line902"></a> * @return {number} The day of week according to universal time and
<a name="line903"></a> *     firstDayOfWeek setting.
<a name="line904"></a> */
<a name="line905"></a>goog.date.Date.prototype.getUTCWeekday = function() {
<a name="line906"></a>  return (this.getUTCIsoWeekday() - this.firstDayOfWeek_ + 7) % 7;
<a name="line907"></a>};
<a name="line908"></a>
<a name="line909"></a>
<a name="line910"></a>/**
<a name="line911"></a> * @return {number} The first day of the week. 0 = Mon, 6 = Sun.
<a name="line912"></a> */
<a name="line913"></a>goog.date.Date.prototype.getFirstDayOfWeek = function() {
<a name="line914"></a>  return this.firstDayOfWeek_;
<a name="line915"></a>};
<a name="line916"></a>
<a name="line917"></a>
<a name="line918"></a>/**
<a name="line919"></a> * @return {number} The cut off weekday used for week number calculations.
<a name="line920"></a> *     0 = Mon, 6 = Sun.
<a name="line921"></a> */
<a name="line922"></a>goog.date.Date.prototype.getFirstWeekCutOffDay = function() {
<a name="line923"></a>  return this.firstWeekCutOffDay_;
<a name="line924"></a>};
<a name="line925"></a>
<a name="line926"></a>
<a name="line927"></a>/**
<a name="line928"></a> * @return {number} The number of days for the selected month.
<a name="line929"></a> */
<a name="line930"></a>goog.date.Date.prototype.getNumberOfDaysInMonth = function() {
<a name="line931"></a>  return goog.date.getNumberOfDaysInMonth(this.getFullYear(), this.getMonth());
<a name="line932"></a>};
<a name="line933"></a>
<a name="line934"></a>
<a name="line935"></a>/**
<a name="line936"></a> * @return {number} The week number.
<a name="line937"></a> */
<a name="line938"></a>goog.date.Date.prototype.getWeekNumber = function() {
<a name="line939"></a>  return goog.date.getWeekNumber(
<a name="line940"></a>      this.getFullYear(), this.getMonth(), this.getDate(),
<a name="line941"></a>      this.firstWeekCutOffDay_, this.firstDayOfWeek_);
<a name="line942"></a>};
<a name="line943"></a>
<a name="line944"></a>
<a name="line945"></a>/**
<a name="line946"></a> * @return {number} The day of year.
<a name="line947"></a> */
<a name="line948"></a>goog.date.Date.prototype.getDayOfYear = function() {
<a name="line949"></a>  var dayOfYear = this.getDate();
<a name="line950"></a>  var year = this.getFullYear();
<a name="line951"></a>  for (var m = this.getMonth() - 1; m &gt;= 0; m--) {
<a name="line952"></a>    dayOfYear += goog.date.getNumberOfDaysInMonth(year, m);
<a name="line953"></a>  }
<a name="line954"></a>
<a name="line955"></a>  return dayOfYear;
<a name="line956"></a>};
<a name="line957"></a>
<a name="line958"></a>
<a name="line959"></a>/**
<a name="line960"></a> * Returns timezone offset. The timezone offset is the delta in minutes between
<a name="line961"></a> * UTC and your local time. E.g., UTC+10 returns -600. Daylight savings time
<a name="line962"></a> * prevents this value from being constant.
<a name="line963"></a> *
<a name="line964"></a> * @return {number} The timezone offset.
<a name="line965"></a> */
<a name="line966"></a>goog.date.Date.prototype.getTimezoneOffset = function() {
<a name="line967"></a>  return this.date_.getTimezoneOffset();
<a name="line968"></a>};
<a name="line969"></a>
<a name="line970"></a>
<a name="line971"></a>/**
<a name="line972"></a> * Returns timezone offset as a string. Returns offset in [+-]HH:mm format or Z
<a name="line973"></a> * for UTC.
<a name="line974"></a> *
<a name="line975"></a> * @return {string} The timezone offset as a string.
<a name="line976"></a> */
<a name="line977"></a>goog.date.Date.prototype.getTimezoneOffsetString = function() {
<a name="line978"></a>  var tz;
<a name="line979"></a>  var offset = this.getTimezoneOffset();
<a name="line980"></a>
<a name="line981"></a>  if (offset == 0) {
<a name="line982"></a>    tz = &#39;Z&#39;;
<a name="line983"></a>  } else {
<a name="line984"></a>    var n = Math.abs(offset) / 60;
<a name="line985"></a>    var h = Math.floor(n);
<a name="line986"></a>    var m = (n - h) * 60;
<a name="line987"></a>    tz = (offset &gt; 0 ? &#39;-&#39; : &#39;+&#39;) +
<a name="line988"></a>        goog.string.padNumber(h, 2) + &#39;:&#39; +
<a name="line989"></a>        goog.string.padNumber(m, 2);
<a name="line990"></a>  }
<a name="line991"></a>
<a name="line992"></a>  return tz;
<a name="line993"></a>};
<a name="line994"></a>
<a name="line995"></a>
<a name="line996"></a>/**
<a name="line997"></a> * Sets the date.
<a name="line998"></a> *
<a name="line999"></a> * @param {goog.date.Date} date Date object to set date from.
<a name="line1000"></a> */
<a name="line1001"></a>goog.date.Date.prototype.set = function(date) {
<a name="line1002"></a>  this.date_ = new Date(date.getFullYear(), date.getMonth(), date.getDate());
<a name="line1003"></a>};
<a name="line1004"></a>
<a name="line1005"></a>
<a name="line1006"></a>/**
<a name="line1007"></a> * Sets the year part of the date.
<a name="line1008"></a> *
<a name="line1009"></a> * @param {number} year Four digit year.
<a name="line1010"></a> */
<a name="line1011"></a>goog.date.Date.prototype.setFullYear = function(year) {
<a name="line1012"></a>  this.date_.setFullYear(year);
<a name="line1013"></a>};
<a name="line1014"></a>
<a name="line1015"></a>
<a name="line1016"></a>/**
<a name="line1017"></a> * Alias for setFullYear.
<a name="line1018"></a> *
<a name="line1019"></a> * @param {number} year Four digit year.
<a name="line1020"></a> * @see #setFullYear
<a name="line1021"></a> */
<a name="line1022"></a>goog.date.Date.prototype.setYear = function(year) {
<a name="line1023"></a>  this.setFullYear(year);
<a name="line1024"></a>};
<a name="line1025"></a>
<a name="line1026"></a>
<a name="line1027"></a>/**
<a name="line1028"></a> * Sets the month part of the date.
<a name="line1029"></a> *
<a name="line1030"></a> * TODO(nnaze): Update type to goog.date.month.
<a name="line1031"></a> *
<a name="line1032"></a> * @param {number} month The month, where 0 = Jan, 11 = Dec.
<a name="line1033"></a> */
<a name="line1034"></a>goog.date.Date.prototype.setMonth = function(month) {
<a name="line1035"></a>  this.date_.setMonth(month);
<a name="line1036"></a>};
<a name="line1037"></a>
<a name="line1038"></a>
<a name="line1039"></a>/**
<a name="line1040"></a> * Sets the day part of the date.
<a name="line1041"></a> *
<a name="line1042"></a> * @param {number} date The day part.
<a name="line1043"></a> */
<a name="line1044"></a>goog.date.Date.prototype.setDate = function(date) {
<a name="line1045"></a>  this.date_.setDate(date);
<a name="line1046"></a>};
<a name="line1047"></a>
<a name="line1048"></a>
<a name="line1049"></a>/**
<a name="line1050"></a> * Sets the value of the date object as expressed in the number of milliseconds
<a name="line1051"></a> * since 1 January 1970 00:00:00.
<a name="line1052"></a> *
<a name="line1053"></a> * @param {number} ms Number of milliseconds since 1 Jan 1970.
<a name="line1054"></a> */
<a name="line1055"></a>goog.date.Date.prototype.setTime = function(ms) {
<a name="line1056"></a>  this.date_.setTime(ms);
<a name="line1057"></a>};
<a name="line1058"></a>
<a name="line1059"></a>
<a name="line1060"></a>/**
<a name="line1061"></a> * Sets the year part of the date according to universal time.
<a name="line1062"></a> *
<a name="line1063"></a> * @param {number} year Four digit year.
<a name="line1064"></a> */
<a name="line1065"></a>goog.date.Date.prototype.setUTCFullYear = function(year) {
<a name="line1066"></a>  this.date_.setUTCFullYear(year);
<a name="line1067"></a>};
<a name="line1068"></a>
<a name="line1069"></a>
<a name="line1070"></a>/**
<a name="line1071"></a> * Sets the month part of the date according to universal time.
<a name="line1072"></a> *
<a name="line1073"></a> * @param {number} month The month, where 0 = Jan, 11 = Dec.
<a name="line1074"></a> */
<a name="line1075"></a>goog.date.Date.prototype.setUTCMonth = function(month) {
<a name="line1076"></a>  this.date_.setUTCMonth(month);
<a name="line1077"></a>};
<a name="line1078"></a>
<a name="line1079"></a>
<a name="line1080"></a>/**
<a name="line1081"></a> * Sets the day part of the date according to universal time.
<a name="line1082"></a> *
<a name="line1083"></a> * @param {number} date The UTC date.
<a name="line1084"></a> */
<a name="line1085"></a>goog.date.Date.prototype.setUTCDate = function(date) {
<a name="line1086"></a>  this.date_.setUTCDate(date);
<a name="line1087"></a>};
<a name="line1088"></a>
<a name="line1089"></a>
<a name="line1090"></a>/**
<a name="line1091"></a> * Sets the first day of week.
<a name="line1092"></a> *
<a name="line1093"></a> * @param {number} day 0 = Mon, 6 = Sun.
<a name="line1094"></a> */
<a name="line1095"></a>goog.date.Date.prototype.setFirstDayOfWeek = function(day) {
<a name="line1096"></a>  this.firstDayOfWeek_ = day;
<a name="line1097"></a>};
<a name="line1098"></a>
<a name="line1099"></a>
<a name="line1100"></a>/**
<a name="line1101"></a> * Sets cut off weekday used for week number calculations. 0 = Mon, 6 = Sun.
<a name="line1102"></a> *
<a name="line1103"></a> * @param {number} day The cut off weekday.
<a name="line1104"></a> */
<a name="line1105"></a>goog.date.Date.prototype.setFirstWeekCutOffDay = function(day) {
<a name="line1106"></a>  this.firstWeekCutOffDay_ = day;
<a name="line1107"></a>};
<a name="line1108"></a>
<a name="line1109"></a>
<a name="line1110"></a>/**
<a name="line1111"></a> * Performs date calculation by adding the supplied interval to the date.
<a name="line1112"></a> *
<a name="line1113"></a> * @param {goog.date.Interval} interval Date interval to add.
<a name="line1114"></a> */
<a name="line1115"></a>goog.date.Date.prototype.add = function(interval) {
<a name="line1116"></a>  if (interval.years || interval.months) {
<a name="line1117"></a>    // As months have different number of days adding a month to Jan 31 by just
<a name="line1118"></a>    // setting the month would result in a date in early March rather than Feb
<a name="line1119"></a>    // 28 or 29. Doing it this way overcomes that problem.
<a name="line1120"></a>
<a name="line1121"></a>    // adjust year and month, accounting for both directions
<a name="line1122"></a>    var month = this.getMonth() + interval.months + interval.years * 12;
<a name="line1123"></a>    var year = this.getYear() + Math.floor(month / 12);
<a name="line1124"></a>    month %= 12;
<a name="line1125"></a>    if (month &lt; 0) {
<a name="line1126"></a>      month += 12;
<a name="line1127"></a>    }
<a name="line1128"></a>
<a name="line1129"></a>    var daysInTargetMonth = goog.date.getNumberOfDaysInMonth(year, month);
<a name="line1130"></a>    var date = Math.min(daysInTargetMonth, this.getDate());
<a name="line1131"></a>
<a name="line1132"></a>    // avoid inadvertently causing rollovers to adjacent months
<a name="line1133"></a>    this.setDate(1);
<a name="line1134"></a>
<a name="line1135"></a>    this.setFullYear(year);
<a name="line1136"></a>    this.setMonth(month);
<a name="line1137"></a>    this.setDate(date);
<a name="line1138"></a>  }
<a name="line1139"></a>
<a name="line1140"></a>  if (interval.days) {
<a name="line1141"></a>    // Convert the days to milliseconds and add it to the UNIX timestamp.
<a name="line1142"></a>    // Taking noon helps to avoid 1 day error due to the daylight saving.
<a name="line1143"></a>    var noon = new Date(this.getYear(), this.getMonth(), this.getDate(), 12);
<a name="line1144"></a>    var result = new Date(noon.getTime() + interval.days * 86400000);
<a name="line1145"></a>
<a name="line1146"></a>    // Set date to 1 to prevent rollover caused by setting the year or month.
<a name="line1147"></a>    this.setDate(1);
<a name="line1148"></a>    this.setFullYear(result.getFullYear());
<a name="line1149"></a>    this.setMonth(result.getMonth());
<a name="line1150"></a>    this.setDate(result.getDate());
<a name="line1151"></a>
<a name="line1152"></a>    this.maybeFixDst_(result.getDate());
<a name="line1153"></a>  }
<a name="line1154"></a>};
<a name="line1155"></a>
<a name="line1156"></a>
<a name="line1157"></a>/**
<a name="line1158"></a> * Returns ISO 8601 string representation of date.
<a name="line1159"></a> *
<a name="line1160"></a> * @param {boolean=} opt_verbose Whether the verbose format should be used
<a name="line1161"></a> *     instead of the default compact one.
<a name="line1162"></a> * @param {boolean=} opt_tz Whether the timezone offset should be included
<a name="line1163"></a> *     in the string.
<a name="line1164"></a> * @return {string} ISO 8601 string representation of date.
<a name="line1165"></a> */
<a name="line1166"></a>goog.date.Date.prototype.toIsoString = function(opt_verbose, opt_tz) {
<a name="line1167"></a>  var str = [
<a name="line1168"></a>    this.getFullYear(),
<a name="line1169"></a>    goog.string.padNumber(this.getMonth() + 1, 2),
<a name="line1170"></a>    goog.string.padNumber(this.getDate(), 2)
<a name="line1171"></a>  ];
<a name="line1172"></a>
<a name="line1173"></a>  return str.join((opt_verbose) ? &#39;-&#39; : &#39;&#39;) +
<a name="line1174"></a>         (opt_tz ? this.getTimezoneOffsetString() : &#39;&#39;);
<a name="line1175"></a>};
<a name="line1176"></a>
<a name="line1177"></a>
<a name="line1178"></a>/**
<a name="line1179"></a> * Returns ISO 8601 string representation of date according to universal time.
<a name="line1180"></a> *
<a name="line1181"></a> * @param {boolean=} opt_verbose Whether the verbose format should be used
<a name="line1182"></a> *     instead of the default compact one.
<a name="line1183"></a> * @param {boolean=} opt_tz Whether the timezone offset should be included in
<a name="line1184"></a> *     the string.
<a name="line1185"></a> * @return {string} ISO 8601 string representation of date according to
<a name="line1186"></a> *     universal time.
<a name="line1187"></a> */
<a name="line1188"></a>goog.date.Date.prototype.toUTCIsoString = function(opt_verbose, opt_tz) {
<a name="line1189"></a>  var str = [
<a name="line1190"></a>    this.getUTCFullYear(),
<a name="line1191"></a>    goog.string.padNumber(this.getUTCMonth() + 1, 2),
<a name="line1192"></a>    goog.string.padNumber(this.getUTCDate(), 2)
<a name="line1193"></a>  ];
<a name="line1194"></a>
<a name="line1195"></a>  return str.join((opt_verbose) ? &#39;-&#39; : &#39;&#39;) + (opt_tz ? &#39;Z&#39; : &#39;&#39;);
<a name="line1196"></a>};
<a name="line1197"></a>
<a name="line1198"></a>
<a name="line1199"></a>/**
<a name="line1200"></a> * Tests whether given date is equal to this Date.
<a name="line1201"></a> * Note: This ignores units more precise than days (hours and below)
<a name="line1202"></a> * and also ignores timezone considerations.
<a name="line1203"></a> *
<a name="line1204"></a> * @param {goog.date.Date} other The date to compare.
<a name="line1205"></a> * @return {boolean} Whether the given date is equal to this one.
<a name="line1206"></a> */
<a name="line1207"></a>goog.date.Date.prototype.equals = function(other) {
<a name="line1208"></a>  return this.getYear() == other.getYear() &amp;&amp;
<a name="line1209"></a>         this.getMonth() == other.getMonth() &amp;&amp;
<a name="line1210"></a>         this.getDate() == other.getDate();
<a name="line1211"></a>};
<a name="line1212"></a>
<a name="line1213"></a>
<a name="line1214"></a>/**
<a name="line1215"></a> * Overloaded toString method for object.
<a name="line1216"></a> * @return {string} ISO 8601 string representation of date.
<a name="line1217"></a> * @override
<a name="line1218"></a> */
<a name="line1219"></a>goog.date.Date.prototype.toString = function() {
<a name="line1220"></a>  return this.toIsoString();
<a name="line1221"></a>};
<a name="line1222"></a>
<a name="line1223"></a>
<a name="line1224"></a>/**
<a name="line1225"></a> * Fixes date to account for daylight savings time in browsers that fail to do
<a name="line1226"></a> * so automatically.
<a name="line1227"></a> * @param {number} expected Expected date.
<a name="line1228"></a> * @private
<a name="line1229"></a> */
<a name="line1230"></a>goog.date.Date.prototype.maybeFixDst_ = function(expected) {
<a name="line1231"></a>  if (this.getDate() != expected) {
<a name="line1232"></a>    var dir = this.getDate() &lt; expected ? 1 : -1;
<a name="line1233"></a>    this.date_.setUTCHours(this.date_.getUTCHours() + dir);
<a name="line1234"></a>  }
<a name="line1235"></a>};
<a name="line1236"></a>
<a name="line1237"></a>
<a name="line1238"></a>/**
<a name="line1239"></a> * @return {number} Value of wrapped date.
<a name="line1240"></a> * @override
<a name="line1241"></a> */
<a name="line1242"></a>goog.date.Date.prototype.valueOf = function() {
<a name="line1243"></a>  return this.date_.valueOf();
<a name="line1244"></a>};
<a name="line1245"></a>
<a name="line1246"></a>
<a name="line1247"></a>/**
<a name="line1248"></a> * Compares two dates.  May be used as a sorting function.
<a name="line1249"></a> * @see goog.array.sort
<a name="line1250"></a> * @param {!goog.date.DateLike} date1 Date to compare.
<a name="line1251"></a> * @param {!goog.date.DateLike} date2 Date to compare.
<a name="line1252"></a> * @return {number} Comparison result. 0 if dates are the same, less than 0 if
<a name="line1253"></a> *     date1 is earlier than date2, greater than 0 if date1 is later than date2.
<a name="line1254"></a> */
<a name="line1255"></a>goog.date.Date.compare = function(date1, date2) {
<a name="line1256"></a>  return date1.getTime() - date2.getTime();
<a name="line1257"></a>};
<a name="line1258"></a>
<a name="line1259"></a>
<a name="line1260"></a>
<a name="line1261"></a>/**
<a name="line1262"></a> * Class representing a date and time. Defaults to current date and time if none
<a name="line1263"></a> * is specified.
<a name="line1264"></a> *
<a name="line1265"></a> * Implements most methods of the native js Date object and can be used
<a name="line1266"></a> * interchangeably with it just as if goog.date.DateTime was a subclass of Date.
<a name="line1267"></a> *
<a name="line1268"></a> * @param {number|Object=} opt_year Four digit year or a date-like object. If
<a name="line1269"></a> *     not set, the created object will contain the date determined by
<a name="line1270"></a> *     goog.now().
<a name="line1271"></a> * @param {number=} opt_month Month, 0 = Jan, 11 = Dec.
<a name="line1272"></a> * @param {number=} opt_date Date of month, 1 - 31.
<a name="line1273"></a> * @param {number=} opt_hours Hours, 0 - 24.
<a name="line1274"></a> * @param {number=} opt_minutes Minutes, 0 - 59.
<a name="line1275"></a> * @param {number=} opt_seconds Seconds, 0 - 61.
<a name="line1276"></a> * @param {number=} opt_milliseconds Milliseconds, 0 - 999.
<a name="line1277"></a> * @constructor
<a name="line1278"></a> * @extends {goog.date.Date}
<a name="line1279"></a> */
<a name="line1280"></a>goog.date.DateTime = function(opt_year, opt_month, opt_date, opt_hours,
<a name="line1281"></a>                              opt_minutes, opt_seconds, opt_milliseconds) {
<a name="line1282"></a>  if (goog.isNumber(opt_year)) {
<a name="line1283"></a>    this.date_ = new Date(opt_year, opt_month || 0, opt_date || 1,
<a name="line1284"></a>                          opt_hours || 0, opt_minutes || 0, opt_seconds || 0,
<a name="line1285"></a>                          opt_milliseconds || 0);
<a name="line1286"></a>  } else {
<a name="line1287"></a>    this.date_ = new Date(opt_year ? opt_year.getTime() : goog.now());
<a name="line1288"></a>  }
<a name="line1289"></a>};
<a name="line1290"></a>goog.inherits(goog.date.DateTime, goog.date.Date);
<a name="line1291"></a>
<a name="line1292"></a>
<a name="line1293"></a>/**
<a name="line1294"></a> * Creates a DateTime from a datetime string expressed in RFC 822 format.
<a name="line1295"></a> *
<a name="line1296"></a> * @param {string} formatted A date or datetime expressed in RFC 822 format.
<a name="line1297"></a> * @return {goog.date.DateTime} Parsed date or null if parse fails.
<a name="line1298"></a> */
<a name="line1299"></a>goog.date.DateTime.fromRfc822String = function(formatted) {
<a name="line1300"></a>  var date = new Date(formatted);
<a name="line1301"></a>  return !isNaN(date.getTime()) ? new goog.date.DateTime(date) : null;
<a name="line1302"></a>};
<a name="line1303"></a>
<a name="line1304"></a>
<a name="line1305"></a>/**
<a name="line1306"></a> * Returns the hours part of the datetime.
<a name="line1307"></a> *
<a name="line1308"></a> * @return {number} An integer between 0 and 23, representing the hour.
<a name="line1309"></a> */
<a name="line1310"></a>goog.date.DateTime.prototype.getHours = function() {
<a name="line1311"></a>  return this.date_.getHours();
<a name="line1312"></a>};
<a name="line1313"></a>
<a name="line1314"></a>
<a name="line1315"></a>/**
<a name="line1316"></a> * Returns the minutes part of the datetime.
<a name="line1317"></a> *
<a name="line1318"></a> * @return {number} An integer between 0 and 59, representing the minutes.
<a name="line1319"></a> */
<a name="line1320"></a>goog.date.DateTime.prototype.getMinutes = function() {
<a name="line1321"></a>  return this.date_.getMinutes();
<a name="line1322"></a>};
<a name="line1323"></a>
<a name="line1324"></a>
<a name="line1325"></a>/**
<a name="line1326"></a> * Returns the seconds part of the datetime.
<a name="line1327"></a> *
<a name="line1328"></a> * @return {number} An integer between 0 and 59, representing the seconds.
<a name="line1329"></a> */
<a name="line1330"></a>goog.date.DateTime.prototype.getSeconds = function() {
<a name="line1331"></a>  return this.date_.getSeconds();
<a name="line1332"></a>};
<a name="line1333"></a>
<a name="line1334"></a>
<a name="line1335"></a>/**
<a name="line1336"></a> * Returns the milliseconds part of the datetime.
<a name="line1337"></a> *
<a name="line1338"></a> * @return {number} An integer between 0 and 999, representing the milliseconds.
<a name="line1339"></a> */
<a name="line1340"></a>goog.date.DateTime.prototype.getMilliseconds = function() {
<a name="line1341"></a>  return this.date_.getMilliseconds();
<a name="line1342"></a>};
<a name="line1343"></a>
<a name="line1344"></a>
<a name="line1345"></a>/**
<a name="line1346"></a> * Returns the day of week according to universal time, US style.
<a name="line1347"></a> *
<a name="line1348"></a> * @return {goog.date.weekDay} Day of week, 0 = Sun, 1 = Mon, 6 = Sat.
<a name="line1349"></a> * @override
<a name="line1350"></a> */
<a name="line1351"></a>goog.date.DateTime.prototype.getUTCDay = function() {
<a name="line1352"></a>  return /** @type {goog.date.weekDay} */ (this.date_.getUTCDay());
<a name="line1353"></a>};
<a name="line1354"></a>
<a name="line1355"></a>
<a name="line1356"></a>/**
<a name="line1357"></a> * Returns the hours part of the datetime according to universal time.
<a name="line1358"></a> *
<a name="line1359"></a> * @return {number} An integer between 0 and 23, representing the hour.
<a name="line1360"></a> * @override
<a name="line1361"></a> */
<a name="line1362"></a>goog.date.DateTime.prototype.getUTCHours = function() {
<a name="line1363"></a>  return this.date_.getUTCHours();
<a name="line1364"></a>};
<a name="line1365"></a>
<a name="line1366"></a>
<a name="line1367"></a>/**
<a name="line1368"></a> * Returns the minutes part of the datetime according to universal time.
<a name="line1369"></a> *
<a name="line1370"></a> * @return {number} An integer between 0 and 59, representing the minutes.
<a name="line1371"></a> * @override
<a name="line1372"></a> */
<a name="line1373"></a>goog.date.DateTime.prototype.getUTCMinutes = function() {
<a name="line1374"></a>  return this.date_.getUTCMinutes();
<a name="line1375"></a>};
<a name="line1376"></a>
<a name="line1377"></a>
<a name="line1378"></a>/**
<a name="line1379"></a> * Returns the seconds part of the datetime according to universal time.
<a name="line1380"></a> *
<a name="line1381"></a> * @return {number} An integer between 0 and 59, representing the seconds.
<a name="line1382"></a> */
<a name="line1383"></a>goog.date.DateTime.prototype.getUTCSeconds = function() {
<a name="line1384"></a>  return this.date_.getUTCSeconds();
<a name="line1385"></a>};
<a name="line1386"></a>
<a name="line1387"></a>
<a name="line1388"></a>/**
<a name="line1389"></a> * Returns the milliseconds part of the datetime according to universal time.
<a name="line1390"></a> *
<a name="line1391"></a> * @return {number} An integer between 0 and 999, representing the milliseconds.
<a name="line1392"></a> */
<a name="line1393"></a>goog.date.DateTime.prototype.getUTCMilliseconds = function() {
<a name="line1394"></a>  return this.date_.getUTCMilliseconds();
<a name="line1395"></a>};
<a name="line1396"></a>
<a name="line1397"></a>
<a name="line1398"></a>/**
<a name="line1399"></a> * Sets the hours part of the datetime.
<a name="line1400"></a> *
<a name="line1401"></a> * @param {number} hours An integer between 0 and 23, representing the hour.
<a name="line1402"></a> */
<a name="line1403"></a>goog.date.DateTime.prototype.setHours = function(hours) {
<a name="line1404"></a>  this.date_.setHours(hours);
<a name="line1405"></a>};
<a name="line1406"></a>
<a name="line1407"></a>
<a name="line1408"></a>/**
<a name="line1409"></a> * Sets the minutes part of the datetime.
<a name="line1410"></a> *
<a name="line1411"></a> * @param {number} minutes Integer between 0 and 59, representing the minutes.
<a name="line1412"></a> */
<a name="line1413"></a>goog.date.DateTime.prototype.setMinutes = function(minutes) {
<a name="line1414"></a>  this.date_.setMinutes(minutes);
<a name="line1415"></a>};
<a name="line1416"></a>
<a name="line1417"></a>
<a name="line1418"></a>/**
<a name="line1419"></a> * Sets the seconds part of the datetime.
<a name="line1420"></a> *
<a name="line1421"></a> * @param {number} seconds Integer between 0 and 59, representing the seconds.
<a name="line1422"></a> */
<a name="line1423"></a>goog.date.DateTime.prototype.setSeconds = function(seconds) {
<a name="line1424"></a>  this.date_.setSeconds(seconds);
<a name="line1425"></a>};
<a name="line1426"></a>
<a name="line1427"></a>
<a name="line1428"></a>/**
<a name="line1429"></a> * Sets the seconds part of the datetime.
<a name="line1430"></a> *
<a name="line1431"></a> * @param {number} ms Integer between 0 and 999, representing the milliseconds.
<a name="line1432"></a> */
<a name="line1433"></a>goog.date.DateTime.prototype.setMilliseconds = function(ms) {
<a name="line1434"></a>  this.date_.setMilliseconds(ms);
<a name="line1435"></a>};
<a name="line1436"></a>
<a name="line1437"></a>
<a name="line1438"></a>/**
<a name="line1439"></a> * Sets the hours part of the datetime according to universal time.
<a name="line1440"></a> *
<a name="line1441"></a> * @param {number} hours An integer between 0 and 23, representing the hour.
<a name="line1442"></a> */
<a name="line1443"></a>goog.date.DateTime.prototype.setUTCHours = function(hours) {
<a name="line1444"></a>  this.date_.setUTCHours(hours);
<a name="line1445"></a>};
<a name="line1446"></a>
<a name="line1447"></a>
<a name="line1448"></a>/**
<a name="line1449"></a> * Sets the minutes part of the datetime according to universal time.
<a name="line1450"></a> *
<a name="line1451"></a> * @param {number} minutes Integer between 0 and 59, representing the minutes.
<a name="line1452"></a> */
<a name="line1453"></a>goog.date.DateTime.prototype.setUTCMinutes = function(minutes) {
<a name="line1454"></a>  this.date_.setUTCMinutes(minutes);
<a name="line1455"></a>};
<a name="line1456"></a>
<a name="line1457"></a>
<a name="line1458"></a>/**
<a name="line1459"></a> * Sets the seconds part of the datetime according to universal time.
<a name="line1460"></a> *
<a name="line1461"></a> * @param {number} seconds Integer between 0 and 59, representing the seconds.
<a name="line1462"></a> */
<a name="line1463"></a>goog.date.DateTime.prototype.setUTCSeconds = function(seconds) {
<a name="line1464"></a>  this.date_.setUTCSeconds(seconds);
<a name="line1465"></a>};
<a name="line1466"></a>
<a name="line1467"></a>
<a name="line1468"></a>/**
<a name="line1469"></a> * Sets the seconds part of the datetime according to universal time.
<a name="line1470"></a> *
<a name="line1471"></a> * @param {number} ms Integer between 0 and 999, representing the milliseconds.
<a name="line1472"></a> */
<a name="line1473"></a>goog.date.DateTime.prototype.setUTCMilliseconds = function(ms) {
<a name="line1474"></a>  this.date_.setUTCMilliseconds(ms);
<a name="line1475"></a>};
<a name="line1476"></a>
<a name="line1477"></a>
<a name="line1478"></a>/**
<a name="line1479"></a> * Performs date calculation by adding the supplied interval to the date.
<a name="line1480"></a> *
<a name="line1481"></a> * @param {goog.date.Interval} interval Date interval to add.
<a name="line1482"></a> * @override
<a name="line1483"></a> */
<a name="line1484"></a>goog.date.DateTime.prototype.add = function(interval) {
<a name="line1485"></a>  goog.date.Date.prototype.add.call(this, interval);
<a name="line1486"></a>
<a name="line1487"></a>  if (interval.hours) {
<a name="line1488"></a>    this.setHours(this.date_.getHours() + interval.hours);
<a name="line1489"></a>  }
<a name="line1490"></a>  if (interval.minutes) {
<a name="line1491"></a>    this.setMinutes(this.date_.getMinutes() + interval.minutes);
<a name="line1492"></a>  }
<a name="line1493"></a>  if (interval.seconds) {
<a name="line1494"></a>    this.setSeconds(this.date_.getSeconds() + interval.seconds);
<a name="line1495"></a>  }
<a name="line1496"></a>};
<a name="line1497"></a>
<a name="line1498"></a>
<a name="line1499"></a>/**
<a name="line1500"></a> * Returns ISO 8601 string representation of date/time.
<a name="line1501"></a> *
<a name="line1502"></a> * @param {boolean=} opt_verbose Whether the verbose format should be used
<a name="line1503"></a> *     instead of the default compact one.
<a name="line1504"></a> * @param {boolean=} opt_tz Whether the timezone offset should be included
<a name="line1505"></a> *     in the string.
<a name="line1506"></a> * @return {string} ISO 8601 string representation of date/time.
<a name="line1507"></a> * @override
<a name="line1508"></a> */
<a name="line1509"></a>goog.date.DateTime.prototype.toIsoString = function(opt_verbose, opt_tz) {
<a name="line1510"></a>  var dateString = goog.date.Date.prototype.toIsoString.call(this, opt_verbose);
<a name="line1511"></a>
<a name="line1512"></a>  if (opt_verbose) {
<a name="line1513"></a>    return dateString + &#39; &#39; +
<a name="line1514"></a>        goog.string.padNumber(this.getHours(), 2) + &#39;:&#39; +
<a name="line1515"></a>        goog.string.padNumber(this.getMinutes(), 2) + &#39;:&#39; +
<a name="line1516"></a>        goog.string.padNumber(this.getSeconds(), 2) +
<a name="line1517"></a>        (opt_tz ? this.getTimezoneOffsetString() : &#39;&#39;);
<a name="line1518"></a>  }
<a name="line1519"></a>
<a name="line1520"></a>  return dateString + &#39;T&#39; +
<a name="line1521"></a>      goog.string.padNumber(this.getHours(), 2) +
<a name="line1522"></a>      goog.string.padNumber(this.getMinutes(), 2) +
<a name="line1523"></a>      goog.string.padNumber(this.getSeconds(), 2) +
<a name="line1524"></a>      (opt_tz ? this.getTimezoneOffsetString() : &#39;&#39;);
<a name="line1525"></a>};
<a name="line1526"></a>
<a name="line1527"></a>
<a name="line1528"></a>/**
<a name="line1529"></a> * Returns XML Schema 2 string representation of date/time.
<a name="line1530"></a> * The return value is also ISO 8601 compliant.
<a name="line1531"></a> *
<a name="line1532"></a> * @param {boolean=} opt_timezone Should the timezone offset be included in the
<a name="line1533"></a> *     string?.
<a name="line1534"></a> * @return {string} XML Schema 2 string representation of date/time.
<a name="line1535"></a> */
<a name="line1536"></a>goog.date.DateTime.prototype.toXmlDateTime = function(opt_timezone) {
<a name="line1537"></a>  return goog.date.Date.prototype.toIsoString.call(this, true) + &#39;T&#39; +
<a name="line1538"></a>      goog.string.padNumber(this.getHours(), 2) + &#39;:&#39; +
<a name="line1539"></a>      goog.string.padNumber(this.getMinutes(), 2) + &#39;:&#39; +
<a name="line1540"></a>      goog.string.padNumber(this.getSeconds(), 2) +
<a name="line1541"></a>      (opt_timezone ? this.getTimezoneOffsetString() : &#39;&#39;);
<a name="line1542"></a>};
<a name="line1543"></a>
<a name="line1544"></a>
<a name="line1545"></a>/**
<a name="line1546"></a> * Returns ISO 8601 string representation of date/time according to universal
<a name="line1547"></a> * time.
<a name="line1548"></a> *
<a name="line1549"></a> * @param {boolean=} opt_verbose Whether the opt_verbose format should be
<a name="line1550"></a> *     returned instead of the default compact one.
<a name="line1551"></a> * @param {boolean=} opt_tz Whether the the timezone offset should be included
<a name="line1552"></a> *     in the string.
<a name="line1553"></a> * @return {string} ISO 8601 string representation of date/time according to
<a name="line1554"></a> *     universal time.
<a name="line1555"></a> * @override
<a name="line1556"></a> */
<a name="line1557"></a>goog.date.DateTime.prototype.toUTCIsoString = function(opt_verbose, opt_tz) {
<a name="line1558"></a>  var dateStr = goog.date.Date.prototype.toUTCIsoString.call(this, opt_verbose);
<a name="line1559"></a>
<a name="line1560"></a>  if (opt_verbose) {
<a name="line1561"></a>    return dateStr + &#39; &#39; +
<a name="line1562"></a>        goog.string.padNumber(this.getUTCHours(), 2) + &#39;:&#39; +
<a name="line1563"></a>        goog.string.padNumber(this.getUTCMinutes(), 2) + &#39;:&#39; +
<a name="line1564"></a>        goog.string.padNumber(this.getUTCSeconds(), 2) +
<a name="line1565"></a>        (opt_tz ? &#39;Z&#39; : &#39;&#39;);
<a name="line1566"></a>  }
<a name="line1567"></a>
<a name="line1568"></a>  return dateStr + &#39;T&#39; +
<a name="line1569"></a>      goog.string.padNumber(this.getUTCHours(), 2) +
<a name="line1570"></a>      goog.string.padNumber(this.getUTCMinutes(), 2) +
<a name="line1571"></a>      goog.string.padNumber(this.getUTCSeconds(), 2) +
<a name="line1572"></a>      (opt_tz ? &#39;Z&#39; : &#39;&#39;);
<a name="line1573"></a>};
<a name="line1574"></a>
<a name="line1575"></a>
<a name="line1576"></a>/**
<a name="line1577"></a> * Tests whether given datetime is exactly equal to this DateTime.
<a name="line1578"></a> *
<a name="line1579"></a> * @param {goog.date.Date} other The datetime to compare.
<a name="line1580"></a> * @return {boolean} Whether the given datetime is exactly equal to this one.
<a name="line1581"></a> * @override
<a name="line1582"></a> */
<a name="line1583"></a>goog.date.DateTime.prototype.equals = function(other) {
<a name="line1584"></a>  return this.getTime() == other.getTime();
<a name="line1585"></a>};
<a name="line1586"></a>
<a name="line1587"></a>
<a name="line1588"></a>/**
<a name="line1589"></a> * Overloaded toString method for object.
<a name="line1590"></a> * @return {string} ISO 8601 string representation of date/time.
<a name="line1591"></a> * @override
<a name="line1592"></a> */
<a name="line1593"></a>goog.date.DateTime.prototype.toString = function() {
<a name="line1594"></a>  return this.toIsoString();
<a name="line1595"></a>};
<a name="line1596"></a>
<a name="line1597"></a>
<a name="line1598"></a>/**
<a name="line1599"></a> * Generates time label for the datetime, e.g., &#39;5:30am&#39;.
<a name="line1600"></a> * By default this does not pad hours (e.g., to &#39;05:30&#39;) and it does add
<a name="line1601"></a> * an am/pm suffix.
<a name="line1602"></a> * TODO(user): i18n -- hardcoding time format like this is bad.  E.g., in CJK
<a name="line1603"></a> *               locales, need Chinese characters for hour and minute units.
<a name="line1604"></a> * @param {boolean=} opt_padHours Whether to pad hours, e.g., &#39;05:30&#39; vs &#39;5:30&#39;.
<a name="line1605"></a> * @param {boolean=} opt_showAmPm Whether to show the &#39;am&#39; and &#39;pm&#39; suffix.
<a name="line1606"></a> * @param {boolean=} opt_omitZeroMinutes E.g., &#39;5:00pm&#39; becomes &#39;5pm&#39;,
<a name="line1607"></a> *                                      but &#39;5:01pm&#39; remains &#39;5:01pm&#39;.
<a name="line1608"></a> * @return {string} The time label.
<a name="line1609"></a> */
<a name="line1610"></a>goog.date.DateTime.prototype.toUsTimeString = function(opt_padHours,
<a name="line1611"></a>                                                       opt_showAmPm,
<a name="line1612"></a>                                                       opt_omitZeroMinutes) {
<a name="line1613"></a>  var hours = this.getHours();
<a name="line1614"></a>
<a name="line1615"></a>  // show am/pm marker by default
<a name="line1616"></a>  if (!goog.isDef(opt_showAmPm)) {
<a name="line1617"></a>    opt_showAmPm = true;
<a name="line1618"></a>  }
<a name="line1619"></a>
<a name="line1620"></a>  // 12pm
<a name="line1621"></a>  var isPM = hours == 12;
<a name="line1622"></a>
<a name="line1623"></a>  // change from 1-24 to 1-12 basis
<a name="line1624"></a>  if (hours &gt; 12) {
<a name="line1625"></a>    hours -= 12;
<a name="line1626"></a>    isPM = true;
<a name="line1627"></a>  }
<a name="line1628"></a>
<a name="line1629"></a>  // midnight is expressed as &quot;12am&quot;, but if am/pm marker omitted, keep as &#39;0&#39;
<a name="line1630"></a>  if (hours == 0 &amp;&amp; opt_showAmPm) {
<a name="line1631"></a>    hours = 12;
<a name="line1632"></a>  }
<a name="line1633"></a>
<a name="line1634"></a>  var label = opt_padHours ? goog.string.padNumber(hours, 2) : String(hours);
<a name="line1635"></a>  var minutes = this.getMinutes();
<a name="line1636"></a>  if (!opt_omitZeroMinutes || minutes &gt; 0) {
<a name="line1637"></a>    label += &#39;:&#39; + goog.string.padNumber(minutes, 2);
<a name="line1638"></a>  }
<a name="line1639"></a>
<a name="line1640"></a>  // by default, show am/pm suffix
<a name="line1641"></a>  if (opt_showAmPm) {
<a name="line1642"></a>    /**
<a name="line1643"></a>     * @desc Suffix for morning times.
<a name="line1644"></a>     */
<a name="line1645"></a>    var MSG_TIME_AM = goog.getMsg(&#39;am&#39;);
<a name="line1646"></a>
<a name="line1647"></a>    /**
<a name="line1648"></a>     * @desc Suffix for afternoon times.
<a name="line1649"></a>     */
<a name="line1650"></a>    var MSG_TIME_PM = goog.getMsg(&#39;pm&#39;);
<a name="line1651"></a>
<a name="line1652"></a>    label += isPM ? MSG_TIME_PM : MSG_TIME_AM;
<a name="line1653"></a>  }
<a name="line1654"></a>  return label;
<a name="line1655"></a>};
<a name="line1656"></a>
<a name="line1657"></a>
<a name="line1658"></a>/**
<a name="line1659"></a> * Generates time label for the datetime in standard ISO 24-hour time format.
<a name="line1660"></a> * E.g., &#39;06:00:00&#39; or &#39;23:30:15&#39;.
<a name="line1661"></a> * @param {boolean=} opt_showSeconds Whether to shows seconds. Defaults to TRUE.
<a name="line1662"></a> * @return {string} The time label.
<a name="line1663"></a> */
<a name="line1664"></a>goog.date.DateTime.prototype.toIsoTimeString = function(opt_showSeconds) {
<a name="line1665"></a>  var hours = this.getHours();
<a name="line1666"></a>  var label = goog.string.padNumber(hours, 2) +
<a name="line1667"></a>              &#39;:&#39; +
<a name="line1668"></a>              goog.string.padNumber(this.getMinutes(), 2);
<a name="line1669"></a>  if (!goog.isDef(opt_showSeconds) || opt_showSeconds) {
<a name="line1670"></a>    label += &#39;:&#39; + goog.string.padNumber(this.getSeconds(), 2);
<a name="line1671"></a>  }
<a name="line1672"></a>  return label;
<a name="line1673"></a>};
<a name="line1674"></a>
<a name="line1675"></a>
<a name="line1676"></a>/**
<a name="line1677"></a> * @return {!goog.date.DateTime} A clone of the datetime object.
<a name="line1678"></a> * @override
<a name="line1679"></a> */
<a name="line1680"></a>goog.date.DateTime.prototype.clone = function() {
<a name="line1681"></a>  var date = new goog.date.DateTime(this.date_);
<a name="line1682"></a>  date.setFirstDayOfWeek(this.getFirstDayOfWeek());
<a name="line1683"></a>  date.setFirstWeekCutOffDay(this.getFirstWeekCutOffDay());
<a name="line1684"></a>  return date;
<a name="line1685"></a>};
</pre>


</body>
</html>
